import os.path

# 1.绝对路径
print(os.path.abspath('.'))
# On most platforms, this is equivalent to calling the function mormpath() as follows:
print(os.path.normpath(os.path.join(os.getcwd(), '.')))

# 2.返回名字
# This is the second element of the pair returned by passing path to the function split().
print(os.path.basename('.'))
print(os.path.basename('D:/DevWorkspace/vs_py/python/ospath'))
print(os.path.basename('D:/DevWorkspace/vs_py/python/ospath/'))

# 3.返回多个路径中相同路劲部分（Unix, Windows）,参数：合法的paths
# Return the longest common sub-path of each pathname in the sequence paths.
print(os.path.commonpath(['d:/DevWorkspace/', 'd:/DevWorkspace/vs_01']))

# 4.获取相同的前缀，参数：list
print(os.path.commonprefix(['/usr/lib', '/usr/local/']))

# 5.返回目录，与basename()相对应
# This is the first element of the pair returned by passing path to the function split().
print(os.path.dirname('.'))
print(os.path.dirname('D:/DevWorkspace/vs_py/python/ospath'))
print(os.path.dirname('D:/DevWorkspace/vs_py/python/ospath/'))

# 6.是否存在。无效链接、无权限返回：False
print(os.path.exists('D:/DevWorkspace/vs_py/python/ospath/'))

# 7.是否存在。无效链接：True，linux?
# Equivalent to exist() on platforms lacking os.lstat(). 
print(os.path.lexists('D:/DevWorkspace/vs_py/python/ospath/alink'))

# 8.将~替换成当前用户目录，~user替换成指定用户目录
print(os.path.expanduser('~'))
print(os.path.expanduser('~user'))

# 9.替换$name和${name}变量
print(os.path.expandvars('${JAVA_HOME}'))
print(os.path.expandvars('%JAVA_HOME%')) # Windows特有

# 10.路径上次被访问的时间，路径必须有效
# Return the time of last access of path.
print(os.path.getatime('/home/mpaster'))

# 11.路径上次被修改的时间，路径必须有效
# Return the time of last modification of path.
print(os.path.getmtime('/home/mpaster'))

# 12.元数据最后改变时间（Unix),创建时间（Windows)
# Return the system's ctime which, on some systems(like Unix) is the time of the last metadata change
# and, on others(like Windows), is the creation time of path.
print(os.path.getctime('/home/mpaster/devworkspace/python/ospath/'))

# 13.返回路径（文件）的大小（bytes）
print(os.path.getsize('/home/mpaster/devworkspace/python/ospath/'))
print(os.path.getsize('/home/mpaster/devworkspace/python/ospath/ospathfuncs.py'))

# 14.是否为绝对路径
print(os.path.isabs('D:/DevWorkspace/vs_py/python/ospath/'))
print(os.path.isabs('.'))

# 15.判断是否为文件
print(os.path.isfile('D:/DevWorkspace/vs_py/python/ospath/ospathfuncs.py'))
print(os.path.isfile('D:/DevWorkspace/vs_py/python/ospath/alink'))

# 16.判断是否为路径
print(os.path.isdir('D:/DevWorkspace/vs_py/python/ospath/ospathfuncs.py'))
print(os.path.isdir('D:/DevWorkspace/vs_py/python/ospath'))
print(os.path.isdir('D:/DevWorkspace/vs_py/python/ospath/'))

# 17.判断是否为链接
# Return True if path refers to an existing directory entry that is symbolic link.
print(os.path.islink('D:/DevWorkspace/vs_py/python/ospath/alink'))

# 18.判断是否为挂载点
print(os.path.ismount('D:/DevWorkspace/vs_py/python/ospath/'))

# 19.拼接多个路径
print(os.path.join(os.getcwd(), 'ospath'))
print(os.path.join(os.getcwd(), '')) # 可以以此补一个\结尾

# 20.处理路径大小写，Windows平台全部处理成小写并处理成反斜杠
# Normalize the case of a pathname.
print(os.path.normcase('D:/DevWorkspace/vs_py/python/ospath/'))

# 21.处理 A//B A/B/ A/./B 和 A/foo/../B 为 A/B
# 会处理掉最后的斜杠
print(os.path.normpath('D:/DevWorkspace/vs_py/./python/foo/../ospath/'))

# 返回真实路径，排除引用标识
print(os.path.realpath('D:/DevWorkspace/vs_py/python/ospath/'))
# os.path.relpath(path, start=os.curdir)
# os.path.samefile(path1, path2)
# os.path.sameopenfile(fp1, fp2)
# os.path.samestat(stat1, stat2)
# os.path.split(path)
# os.path.splitdriver(path)
# os.path.splitext(path)
# os.path.supports_unicode_filenames